﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using ThanNhanTao.Server;
using ThanNhanTao.Server.Entities;
using ThanNhanTao.Server.BLL;


namespace ThanNhanTao
{
    /// <summary>
    /// Interaction logic for frmPhieuThongTinHoSoCongChucVienChuc.xaml
    /// </summary>
    public partial class frmTrinhDoChuyenMon : DXWindow
    {
        #region Fields

        private HoSoNhanSuEntities hoSoHienTai;
        private HoSoNhanSuBLL hoSoNhanSuBLL;
        private List<Dm_DanToc> listDanToc;

        #endregion

        #region Properties

        public HoSoNhanSuEntities HoSoHienTai
        {
            get
            {
                if (hoSoHienTai == null)
                    return new HoSoNhanSuEntities();
                return hoSoHienTai;
            }
            set
            {
                hoSoHienTai = value;
            }
        }

        public bool LaThemMoi
        {
            get
            {
                return HoSoHienTai.IdHoSoNhanSu == 0;
            }
        }

        #endregion

        public frmTrinhDoChuyenMon()
        {
            InitializeComponent();
            try
            {
                hoSoNhanSuBLL = new HoSoNhanSuBLL();
                LoadForm();
            }
            catch (Exception)
            {
                DXMessageBox.Show("Thiết lập thông tin không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        public void LoadForm()
        {
        }

        #region Method

        public void SetEnableButton(bool buttonThemMoi, bool buttonLuu, bool buttonXoa)
        {
            btnLuu.IsEnabled = buttonLuu;
            btnThemMoi.IsEnabled = buttonThemMoi;
            btnXoa.IsEnabled = buttonXoa;
        }

        public void ThemMoi()
        {
            //txtHo.Clear();
            //txtTen.Clear();
            //rdoNam.IsChecked = true;
            //txtNgaySinh.Clear();
            //txtThangSinh.Clear();
            //txtNamSinh.Clear();
            //cboDanToc.EditValue = null;
            //txtTinhTrangHonNhan.Clear();
            //txtDiaChiThuongTru.Clear();
            //txtNguyenQuan.Clear();
            //txtSoHieuCongChuc.Clear();
            //txtDienThoaiDiDong.Clear();
            //txtDiaChiEmail.Clear();
            //rdoDangVienKhong.IsChecked = false;
            //rdoDangVienCo.IsChecked = false;
            //deKetNap.EditValue = null;
            //deChinhThuc.EditValue = null;
            //txtChucVuDang.Clear();
            //HoSoHienTai = new HoSoNhanSuEntities();
        }

        public void BindHoSoNhanSuHienTai(HoSoNhanSuEntities hoSo)
        {
            //this.hoSoHienTai = hoSo;
            //txtHo.Text = hoSoHienTai.Ho;
            //txtTen.Text = hoSoHienTai.Ten;
            //if (hoSoHienTai.GioiTinh)
            //    rdoNam.IsChecked = true;
            //else
            //    rdoNu.IsChecked = true;
            //if (hoSoHienTai.NgaySinh != null)
            //{
            //    txtNgaySinh.Text = hoSoHienTai.NgaySinh.Value.Day.ToString();
            //    txtThangSinh.Text = hoSoHienTai.NgaySinh.Value.Month.ToString();
            //}
            //else
            //{
            //    txtNgaySinh.Clear();
            //    txtThangSinh.Clear();
            //}
            //txtNamSinh.Text = hoSoHienTai.NamSinh.ToString();
            //cboDanToc.EditValue = listDanToc.FirstOrDefault(u => u.MaDanToc == hoSoHienTai.MaDanToc);
            //txtTinhTrangHonNhan.Text = hoSoHienTai.TinhTrangHonNhan;
            //txtDiaChiThuongTru.Text = hoSoHienTai.DiaChiThuongTru;
            //txtNguyenQuan.Text = hoSoHienTai.NguyenQuan;
            //txtSoHieuCongChuc.Text = hoSoHienTai.SoHieuCongChuc;
            //txtDienThoaiDiDong.Text = hoSoHienTai.DienThoaiDiDong;
            //txtDiaChiEmail.Text = hoSoHienTai.DiaChiEmail;
            //if (hoSoHienTai.LaDangVien)
            //    rdoDangVienCo.IsChecked = true;
            //else
            //    rdoDangVienKhong.IsChecked = true;
            //if (hoSoHienTai.NgayKetNapDang != null)
            //    deKetNap.EditValue = hoSoHienTai.NgayKetNapDang.Value;
            //else
            //    deKetNap.EditValue = null;
            //if (hoSoHienTai.NgayChinhThucVaoDang != null)
            //    deChinhThuc.EditValue = hoSoHienTai.NgayChinhThucVaoDang.Value;
            //else
            //    deChinhThuc.EditValue = null;
            //txtChucVuDang.Text = hoSoHienTai.ChucVuDang;
        }

        #endregion

        #region Events

        private void btnLuu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //if (hoSoHienTai == null)
                //    hoSoHienTai = new HoSoNhanSuEntities();
                //Dm_DanToc danToc = cboDanToc.EditValue as Dm_DanToc;
                //hoSoHienTai.Ho = txtHo.Text;
                //hoSoHienTai.Ten = txtTen.Text;
                //hoSoHienTai.GioiTinh = rdoNam.IsChecked == true;
                //if (!string.IsNullOrEmpty(txtNgaySinh.Text) && !string.IsNullOrEmpty(txtThangSinh.Text) && !string.IsNullOrEmpty(txtNamSinh.Text))
                //    hoSoHienTai.NgaySinh = new DateTime(Convert.ToInt32(txtNamSinh.Text) 
                //                                        , Convert.ToInt32(txtThangSinh.Text)
                //                                        , Convert.ToInt32(txtNgaySinh.Text));
                //hoSoHienTai.NamSinh = Convert.ToInt32(txtNamSinh.Text);
                //hoSoHienTai.Tuoi = (short)(DateTime.UtcNow.Year - Convert.ToInt32(txtNamSinh.Text));
                //if (danToc != null)
                //    hoSoHienTai.MaDanToc = danToc.MaDanToc; ;
                //hoSoHienTai.TinhTrangHonNhan = txtTinhTrangHonNhan.Text;
                //hoSoHienTai.DiaChiThuongTru = txtDiaChiThuongTru.Text;
                //hoSoHienTai.NguyenQuan = txtNguyenQuan.Text;
                //hoSoHienTai.SoHieuCongChuc = txtSoHieuCongChuc.Text;
                //hoSoHienTai.DienThoaiDiDong = txtDienThoaiDiDong.Text;
                //hoSoHienTai.DiaChiEmail = txtDiaChiEmail.Text;
                //hoSoHienTai.LaDangVien = rdoDangVienCo.IsChecked == true;
                //if (!string.IsNullOrEmpty(deKetNap.DisplayText))
                //    hoSoHienTai.NgayKetNapDang = Convert.ToDateTime(deKetNap.EditValue);
                //else
                //    hoSoHienTai.NgayKetNapDang = null;
                //if (!string.IsNullOrEmpty(deChinhThuc.DisplayText))
                //    hoSoHienTai.NgayChinhThucVaoDang = Convert.ToDateTime(deChinhThuc.EditValue);
                //else
                //    hoSoHienTai.NgayChinhThucVaoDang = null;
                //hoSoHienTai.ChucVuDang = txtChucVuDang.Text;
                //if (LaThemMoi)
                //{
                //    hoSoNhanSuBLL.AddHoSoNhanSu(ref hoSoHienTai);
                //    ucDanhSach.AddHoSoNhanSuToGrid(hoSoHienTai);
                //}
                //else
                //{
                //    hoSoNhanSuBLL.UpdateHoSoNhanSu(hoSoHienTai);
                //    ucDanhSach.UpdateHoSoNhanSuToGrid(hoSoHienTai);
                //}
                DXMessageBox.Show("Lưu thông tin thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception)
            {
                DXMessageBox.Show("Lưu thông tin không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnInPhieu_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnDong_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnXoa_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //hoSoNhanSuBLL.DeleteHoSoNhanSu(hoSoHienTai.IdHoSoNhanSu);
                //ucDanhSach.DeleteHoSoNhanSuToGrid(hoSoHienTai.IdHoSoNhanSu);
                //btnThemMoi.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                DXMessageBox.Show("Xóa thông tin thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception)
            {
                DXMessageBox.Show("Xóa thông tin không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnThemMoi_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ThemMoi();
            }
            catch (Exception)
            {
                DXMessageBox.Show("Thêm mới không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void txtHo_KeyUp(object sender, KeyEventArgs e)
        {
            SetEnableButton(true, true, true);
        }

        #endregion

        
    }
}
